<template>
  <view class="off-balance-funds-form">
    <navbar/>
    <u--form ref="form" :model="temp" label-position="top">
      <u-form-item label="标题:" prop="title">
        <u--input v-model="temp.title" placeholder="请输入标题"/>
      </u-form-item>
      <u-form-item label="受益人:" prop="userId">
        <system-user v-model="temp.userId" placeholder="请选择用户"/>
      </u-form-item>
      <u-form-item label="垫资人:" prop="fundUserId">
        <system-user v-model="temp.fundUserId" placeholder="请选择垫资人"/>
      </u-form-item>
      <u-form-item label="项目名称:" prop="projectName">
        <u--input v-model="temp.projectName" placeholder="请输入项目名称"/>
      </u-form-item>
      <u-form-item>
        <view class="time-money">
          <u-form-item label="发生时间:" prop="date">
            <date-picker v-model="temp.date" placeholder="请选择发生时间" type="date" pattern="{y}-{m}-{d}"/>
          </u-form-item>
          <u-form-item label="金额:" prop="money">
            <u--input v-model="temp.money" placeholder="请输入报销金额"/>
          </u-form-item>
        </view>
      </u-form-item>
      <u-form-item label="附件:" prop="file">
        <upload-image v-model="temp.file" dir="temp.file"/>
      </u-form-item>
      <u-form-item label="备注:" prop="remarks">
        <u--input v-model="temp.remarks" placeholder="请输入备注内容"/>
      </u-form-item>
      <u-button :loading="loading" class="submit-button" type="primary" shape="circle" @click="submit">提交</u-button>
    </u--form>
  </view>

</template>

<script>
// import {
//   getoffBalanceFunds,
//   createoffBalanceFunds,
//   updateoffBalanceFunds
// } from '@/api/applyForReimbursement/offBalanceFunds'
import SystemUser from '@/components/System/systemUser'
import DatePicker from '@/components/Picker/datePicker'
import UploadImage from '@/components/Upload/uploadImage'

export default {
  name: 'RecoverableForm',
  components: {
    SystemUser,
    DatePicker,
    UploadImage
  },
  data() {
    return {
      loading: false,
      temp: {},
      rules: {}
    }
  },
  onLoad(query) {
    this.temp.id = query.id
    if (this.temp.id) {
      this.getDetail(query.id)
    }
  },
  onReady() {
    this.$refs.form.setRules(this.rules)
  },
  methods: {
    // 获取详情
    // getDetail(id) {
    //   getoffBalanceFunds(id).then(response => {
    //     if (response.data.success) {
    //       this.temp = response.data.data
    //     }
    //   })
    // },
    // 提交表单
    submit() {
      if (this.isNull(this.rules)) {
        !this.temp.id ? this.create() : this.update()
        return
      }
      this.$refs.form.validate().then(() => {
        !this.temp.id ? this.create() : this.update()
      })
    }
    // 新建
    // create() {
    //   this.loading = true
    //   createoffBalanceFunds(this.temp).then(response => {
    //     this.loading = false
    //     if (response.data.success) {
    //       this.$uni.showToast(response.data.msg)
    //       this.$uni.goBack()
    //     }
    //   })
    // },
    // 更新
    // update() {
    //   this.loading = true
    //   updateoffBalanceFunds(this.temp).then(response => {
    //     this.loading = false
    //     if (response.data.success) {
    //       this.$uni.showToast(response.data.msg)
    //       this.$uni.goBack()
    //     }
    //   })
    // }
  }
}
</script>
